package com.bcu.calculus.utils;

import com.bcu.calculus.entity.CheckAttendance;
import com.bcu.calculus.entity.CheckAttendanceNumber;
import com.bcu.calculus.entity.CheckMessage;
import com.bcu.calculus.entity.CheckMessageNumber;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CheckMessageUtil {

    public static CheckMessage change(CheckMessageNumber checkMessageNumber) throws ParseException {
        CheckMessage checkMessage = new CheckMessage();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");

        if (checkMessageNumber.getCheckMessageId() != null){
            checkMessage.setCheckMessageId(checkMessageNumber.getCheckMessageId());
        }

        if (checkMessageNumber.getCheckAttendanceId() != null){
            checkMessage.setCheckAttendanceId(checkMessageNumber.getCheckAttendanceId());
        }

        if (checkMessageNumber.getCheckUserId() != null){
            checkMessage.setCheckUserId(checkMessageNumber.getCheckUserId());
        }

        if (checkMessageNumber.getCheckUserName() != null){
            checkMessage.setCheckUserName(checkMessageNumber.getCheckUserName());
        }

        if (checkMessageNumber.getCheckType() != null){
            checkMessage.setCheckType(checkMessageNumber.getCheckType());
        }

        if (checkMessageNumber.getCheckScore() != null){
            checkMessage.setCheckScore(checkMessageNumber.getCheckScore());
        }

        try {
            if(checkMessageNumber.getCheckCreateTime() != null){
                Date Time = formatter.parse(checkMessageNumber.getCheckCreateTime());

                checkMessage.setCheckCreateTime(Time);
            }
        } catch (Exception e) {
            checkMessage.setCheckCreateTime(null);
        }
        return checkMessage;
    }
}
